package com.mentaleye.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mentaleye.dal.dao.StudentDisciplineDao;
import com.mentaleye.dal.model.StudentDiscipline;
import com.mentaleye.dal.model.StudentDisciplineExample;
import com.mentaleye.dal.model.StudentDisciplineExample.Criteria;
import com.mentaleye.service.StudentDisciplineService;

@Service
public class StudentDisciplineServiceImpl implements StudentDisciplineService {

	@Autowired private StudentDisciplineDao dataDao;
	
	@Override
	public boolean insertRecord(StudentDiscipline data) {
		return this.dataDao.insertRecord(data);
	}

	@Override
	public boolean updateRecord(StudentDiscipline data) {
		return this.dataDao.updateRecord(data);
	}

	@Override
	public StudentDiscipline getRecordById(int disciplineId) {
		StudentDiscipline discipline=null;
		StudentDisciplineExample example=new StudentDisciplineExample();
		Criteria criteria = example.createCriteria();
		criteria.andDisciplineIdEqualTo(disciplineId);
		List<StudentDiscipline> dataList = this.dataDao.getListByExample(example);
		if(!dataList.isEmpty()){
			discipline=dataList.get(0);
		}
		return discipline;
	}
	
	@Override
	public List<StudentDiscipline> getList() {
		StudentDisciplineExample example=new StudentDisciplineExample();
		return this.dataDao.getListByExample(example);
	}

	@Override
	public List<StudentDiscipline> getListByType(int typeId) {
		StudentDisciplineExample example=new StudentDisciplineExample();
		Criteria criteria = example.createCriteria();
		criteria.andDisciplineTypeEqualTo(typeId);
		return this.dataDao.getListByExample(example);
	}
	
	@Override
	public List<Map<String,Object>> getListByMap(Map<String, Object> map) {
		return this.dataDao.getListByMap(map);
	}

	@Override
	public boolean deleteByList(List<Integer> idList) {
		StudentDisciplineExample example=new StudentDisciplineExample();
		Criteria criteria = example.createCriteria();
		criteria.andDisciplineIdIn(idList);
		return this.dataDao.deleteByExample(example);
	}
}
